/*
* Simple Mesh Object
*/
#pragma once

#include <GL/glew.h>
#include <string>
#include <glm/glm.hpp>
#include <vector>
#include <memory>

namespace teflon
{
	class Mesh1
	{
	public:
		GLfloat* vp = nullptr;  // 3
		GLfloat* vn = nullptr;  // 3
		GLfloat* vt = nullptr;  // 2
		int num_vertices = 0;

	public:
		Mesh1(const std::string& filepath);
		~Mesh1();
	};

	struct MeshVertex
	{
		// basic sample
		glm::vec3 pos;
		glm::vec3 normal;  // can also be used as vertex color
		glm::vec2 uv;
	};

	// mesh object with vertex buffer
	class Mesh
	{
	private:
		GLuint vao = -1;
		GLuint vbo = -1;
		GLuint ibo = -1;
		uint32_t num_indices = 0;

	public:
		static std::shared_ptr<Mesh> plane();
		static std::shared_ptr<Mesh> square();
		static std::shared_ptr<Mesh> box();

		Mesh();
		~Mesh();

		void SetData(const std::vector<MeshVertex>& vertices,
			const std::vector<uint16_t>& indices);

		void Load(const std::string& filepath);
		void Bind() const { glBindVertexArray(vao); }
		void Unbind() const { glBindVertexArray(0); }
		uint32_t NumIndices() const { return num_indices; }
	};
}
